<template>
    <!-- Vue3组件中的模板结构可以没有根标签 -->
    <h1>一个人的信息 </h1>
    <h2>姓名：{{person.name}}</h2>
    <h2>年龄：{{person.age}}</h2>
    <h2>工作种类：{{person.job.type}}</h2>
    <h2>工作薪水：{{person.job.salary}}</h2>
    <h2>爱好：{{person.hobby}}</h2>
    <button @click="changeInfo">修改人的信息</button>
</template>

<script>
  import {ref,reactive} from 'vue'
  export default {
    name: 'App',
    setup(){
      //数据
      let name = ref('张三')
      let age = ref(18)
      let job = reactive({
        type:'后端工程师',
        salary:'3k'
      })

      let hobby = reactive(['抽烟','喝酒','烫头'])


      /* let person = {
        name:'张三',
        age:18,
        job:{
          type:'后端工程师',
          salary:'3k'
        },
        hobby:['抽烟','喝酒','烫头']
      } */

      // let p = reactive(person)
      let person = reactive({
        name:'张三',
        age:18,
        job:{
          type:'后端工程师',
          salary:'3k'
        },
        hobby:['抽烟','喝酒','烫头']
      })


      //方法
      function changeInfo(){
        // name.value = '李四'
        // age.value = 28
        // job.type = 'sql'


        person.name = '李四',
        person.age = 38,
        person.job.type = 'javascript'

        person.hobby[0] = '学习'
      }

      //返回一个对象（常用）
      return {
        name,
        age,
        changeInfo,
        job,
        hobby,
        person
      }

    },
  }
</script>

